package br.com.ordersys.web.data.listeners;

import java.sql.Timestamp;

import br.com.ordersys.framework.db.DBSessionManager;
import br.com.ordersys.framework.db.EntityLifeCicleListenerAdapter;
import br.com.ordersys.framework.db.IEntityLifeCicleContext;
import br.com.ordersys.framework.db.IValueObject;
import br.com.ordersys.framework.db.config.EntityLifeCicle;

@EntityLifeCicle("Usuario")
public class UsuarioLifeCicleListener extends EntityLifeCicleListenerAdapter{

	@Override
	public void beforeUpdate(IEntityLifeCicleContext dmc) {
		if(dmc.isModifying("DHULTLOGIN")){
			IValueObject loginVO = DBSessionManager.getCurrentSession().emptyVO("RegistroLogin");
			
			loginVO.set("IDUSUARIO", dmc.getNewVO().asInt("IDUSUARIO"));
			loginVO.set("DHLOGIN", dmc.getNewVO().asTimestamp("DHULTLOGIN"));
			
			loginVO.save();
		}
		
		if(dmc.isModifying("PSW")){
			dmc.getNewVO().set("ULTPSW", new Timestamp(System.currentTimeMillis()));
		}
	}
}
